<script setup lang="ts">
import { useMenus } from '@/composables/useMenus'
const { topMenus, getAllMenus, form, onSubmit } = useMenus()

import { useRoute } from 'vue-router'
const route = useRoute()
console.log(route.params.id)

getAllMenus()

// const allMenus = ref([] as MenuItem[])

// const getAllMenus = async () => {
//   const { data } = await getAll()
//   if (data.code === '000000') {
//     menus.value = res.data.data
//   } else {
//     ElMessage.error('获取菜单列表信息失败！')
//     throw new Error('获取菜单列表信息失败！')
//   }
// }
// getAllMenus()

//顶级菜单获取
// const topMenus = computed(() => menus.value.filter((menu) => menu.level === 0))
</script>

<template>
  <el-form :model="form" label-width="auto" size="large">
    <el-form-item label="菜单名称">
      <el-input v-model="form.name" />
    </el-form-item>

    <el-form-item label="菜单路径">
      <el-input v-model="form.href" />
    </el-form-item>

    <el-form-item label="上级菜单">
      <el-select v-model="form.parentId" placeholder="please select your zone">
        <el-option label="顶级菜单" :value="-1" />
        <el-option v-for="menu in topMenus" :key="menu.id" :label="menu.name" :value="menu.id" />
      </el-select>
    </el-form-item>

    <el-form-item label="描述">
      <el-input v-model="form.description" />
    </el-form-item>

    <el-form-item label="图标名称">
      <el-input v-model="form.icon" />
    </el-form-item>

    <el-form-item label="是否显示">
      <el-radio-group v-model="form.shown">
        <el-radio :label="true">是</el-radio>
        <el-radio :label="false">否</el-radio>
      </el-radio-group>
    </el-form-item>

    <el-form-item label="排序">
      <el-input v-model="form.orderNum" />
    </el-form-item>

    <el-form-item>
      <el-button type="primary" @click="onSubmit">立即创建</el-button>
    </el-form-item>
  </el-form>
</template>

<style lang="scss" scoped></style>
